<?php
//


// 个人空间信息

function dr_my_zone_info($uid, $name = '', $cache = -1) {

    $data = \Phpcmf\Service::L('cache')->get_data('my_zone_info-info-'.$uid);
    if (!$data) {
        // 主表
        $data = \Phpcmf\Service::M()->table(SITE_ID.'_zone')->where('uid', $uid)->getRow();
        if (!$data) {
            return [];
        }

        $id = intval($data['id']);
        $tableid = intval($data['tableid']);

        $data2 = \Phpcmf\Service::M()->table(SITE_ID.'_zone_data_'.$tableid)->get($id);
        $data2 && $data = $data2 + $data;

        $data2 = \Phpcmf\Service::M()->table(SITE_ID.'_zone_category_data')->get($id);
        if ($data2) {
            $data = $data2 + $data;
            $data2 = \Phpcmf\Service::M()->table(SITE_ID.'_zone_category_data_'.$tableid)->get($id);
            $data2 && $data = $data2 + $data;
        }

        $data = \Phpcmf\Service::L('Field')->app('zone')->format_value(\Phpcmf\Service::L('cache')->get('module-'.SITE_ID.'-zone', 'field'), $data, 1);

        SYS_CACHE && \Phpcmf\Service::L('cache')->set_data('member-info-'.$uid, $data, $cache > 0 ? $cache : SYS_CACHE_SHOW * 3600);
    }

    return $name ? $data[$name] : $data;
}